(function() {
	var colors = ["#D61C59", "#E7D84B", "#1B8798"];
	var characters = ["🤣", "😘", "😍", "😜"];
	var elementGroup = [];

	// 定义元素类
	class MouseEffectElement {
		constructor() {
			this.character = characters[Math.floor(Math.random() * characters.length)];
			this.lifeSpan = 120;
			this.initialStyles = {
				position: "fixed",
				top: "0",
				display: "block",
				pointerEvents: "none",
				zIndex: "10000000",
				fontSize: "25px",
				willChange: "transform",
				color: "#000000"
			};
		}

		init(x, y, color) {
			this.velocity = {
				x: (Math.random() < .5 ? -1 : 1) * (Math.random() / 2),
				y: 1
			};
			this.position = {
				x: x - 10,
				y: y - 20
			};
			this.initialStyles.color = color;
			this.element = document.createElement("span");
			this.element.innerHTML = this.character;
			applyStyle(this.element, this.initialStyles);
			this.update();
			document.body.appendChild(this.element);
		}

		update() {
			this.position.x += this.velocity.x;
			this.position.y += this.velocity.y;
			this.lifeSpan--;
			this.element.style.transform =
				`translate3d(${this.position.x}px, ${this.position.y}px, 0) scale(${this.lifeSpan / 120})`;
		}

		die() {
			this.element.parentNode.removeChild(this.element);
		}
	}

	var lastCreateTime = 0;
	var createInterval = 200; // 每200毫秒生成一个表情

	function addListener() {
		document.addEventListener("mousemove", onMouseMove);
		document.addEventListener("touchmove", onTouchMove);
		document.addEventListener("touchstart", onTouchStart);
	}

	function render() {
		for (var i = 0; i < elementGroup.length; i++) {
			elementGroup[i].update();
			if (elementGroup[i].lifeSpan < 0) {
				elementGroup[i].die();
				elementGroup.splice(i, 1);
			}
		}
	}

	function onMouseMove(event) {
		var now = Date.now();
		if (now - lastCreateTime >= createInterval) {
			var color = colors[Math.floor(Math.random() * colors.length)];
			createElement(event.clientX, event.clientY, color);
			lastCreateTime = now;
		}
	}

	function onTouchMove(event) {
		var now = Date.now();
		if (event.touches.length > 0 && now - lastCreateTime >= createInterval) {
			for (var i = 0; i < event.touches.length; i++) {
				var color = colors[Math.floor(Math.random() * colors.length)];
				createElement(event.touches[i].clientX, event.touches[i].clientY, color);
			}
			lastCreateTime = now;
		}
	}

	function onTouchStart(event) {
		onTouchMove(event);
	}

	function createElement(x, y, color) {
		var element = new MouseEffectElement();
		element.init(x, y, color);
		elementGroup.push(element);
	}

	function applyStyle(element, style) {
		for (var key in style) {
			element.style[key] = style[key];
		}
	}

	addListener();
	setInterval(render, 1000 / 60);
})();